//
//  UIButton+Extension.swift
//  武汉微博
//
//  Created by 谌桃 on 16/9/24.
//  Copyright © 2016年 ryan.chen. All rights reserved.
//

import UIKit

extension UIButton{

    ///UIButton 的便利构造方法
    convenience init(
        titleName:String,
        titleColor:UIColor,
        imageName:String? = nil,
        backImageName:String? = nil) {
        
        self.init()
        
        self.setTitle(titleName, forState: .Normal)
        self.setTitleColor(titleColor, forState: .Normal)
        
        if let imageName = imageName {
        
            self.setImage(UIImage(named: imageName), forState: .Normal)
            self.setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        }
        
        if let backImageName = backImageName {
            self.setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
            self.setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState:.Highlighted)
        }
        
        self.sizeToFit()
    }
}
